/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.app.controller;

import com.app.entity.Log;
import com.app.entity.Usuario;
import com.app.sessionBeans.LogFacade;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author EduardoAlexis
 */
@Named(value = "logController")
@RequestScoped
public class LogController {
    @EJB
    private LogFacade logFacade;
    private List <Log> itemsLog = null;
    private List <Log> allItemsLog=null;
    private List <Log> filteredLogs;
    @Inject
    UsuarioController uc;

    /**
     * Creates a new instance of LogController
     */
    
    public LogController() {
    }

    public LogFacade getLogFacade() {
        return logFacade;
    }

    public List<Log> getItemsLog() {
        if (uc.getSelected()!=null ){
        Usuario userlog = uc.getUsuarioFacade().findUsuarioByUsername(uc.getSelected().getUsername());
        itemsLog = getLogFacade().getLogUsuario(userlog);
        return itemsLog;
        }else{
        return null;
        }

    }

    public List<Log> getAllItemsLog() {
           if (allItemsLog==null){
        
        allItemsLog=getLogFacade().findAll();
        for (Log lista1 : allItemsLog){
        
        java.sql.Date sqlDate = new java.sql.Date(lista1.getFecha().getTime());
        lista1.setFecha(sqlDate);
        
        
        }
        }
        return allItemsLog;
    }

    public List<Log> getFilteredLogs() {
        return filteredLogs;
    }

    public void setFilteredLogs(List<Log> filteredLogs) {
        this.filteredLogs = filteredLogs;
    }
    
    
}
